import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/views/layout/Layout'

/* Router Modules */
// import componentsRouter from './modules/components'
// import chartsRouter from './modules/charts'
// import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'
import nestedRouter from './modules/nested'
import productAdminRouter from './modules/productAdmin'
import appraiserAdminRouter from './modules/appraiserAdmin'
import shoppingCentreRouter from './modules/shopping'
import userCentreRouter from './modules/userCenter'
import warehouseCenter from './modules/warehouse'
import marketing from './modules/marketing'
import payCenter from './modules/payCenter'
import activity from './modules/activity'

/** note: Submenu only appear when children.length>=1
 *  detail see  https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 **/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']     will control the page roles (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if true ,the page will no be cached(default is false)
  }
**/
export const constantRouterMap = [
  {
    path: '/',
    redirect: '/login',
  },
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/errorPage/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/errorPage/401'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: '/dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: {
           title: '首页',
           icon: 'dashboard',
            noCache: true ,
            roles :1
        }
      }
    ]
  },
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap,
  mode: 'history'
})

export const asyncRouterMap = [
    {
      path: "/system",
      component: Layout,
      redirect: "/system/Institution",
      name: "system",
      alwaysShow: true,
      meta: {
        title: "系统管理",
        icon: "xitong",
        roles:'system_manager'//页面需要的权限
      },
      children: [
        {
          path: "/system/Menu",
          component: () => import("@/views/system/Menu/Menu"),
          name: "Menu",
          meta: {
            title: "菜单管理",
            roles: 'menu_manager',
            noCache: true,
          }
        },
        {
          path: "/system/Role",
          component: () => import("@/views/system/Role/Role"),
          name: "Role",
          meta: {
            title: "角色管理",
            roles: 'role_manager',
            noCache: true,
          }
        },
      {
        path: "/system/Institution",
        component: () =>
          import("@/views/system/Institution/Institution"),
        name: "Institution",
        meta: {
          title: "机构管理",
          roles: 'org_manager',//页面需要的权限
          noCache: true,
        }
      },{
        path: "/system/Job",
        component: () => import("@/views/system/Job/Job"),
        name: "Job",
        meta: {
          title: "职位管理",
          roles: 'post_manager',
          noCache: true,
        },
      },{
        path: "/system/Staff",
        component: () => import("@/views/system/Staff/Staff"),
        name: "Staff",
        meta: {
          title: "员工管理",
          roles: 'emp_manager',
          noCache: true,
        }
      },
    ]},
    {
      path: "/CommonConfig",
      component: Layout,
      redirect: "/CommonConfig/Config",
      name: "CommonConfig",
      alwaysShow: true,
      meta: {
        title: "公共配置",
        icon: "gonggong",
        roles: 'basic_config'
      },children :[{
        path: "/CommonConfig/Config",
        component: () => import("@/views/CommonConfig/Config/Config"),
        name: "Config",
        meta: {
          title: "字典参数配置",
          roles:'basic_config_param',
          noCache: true,
        }
      },{
        path: "/CommonConfig/Channel",
        component: () => import("@/views/CommonConfig/Channel/Channel"),
        name: "Channel",
        meta: {
          title: "渠道配置",
          roles: 'basic_config_channel',
          noCache: true,
        }
      },{
        path: "/CommonConfig/application",
        component: () => import("@/views/CommonConfig/application/application"),
        name: "application",
        meta: {
          title: "应用配置",
          roles: 'quote_admin',
          noCache: true,
        }
      },{
        path: "/CommonConfig/application/applicationDetails",
        component: () => import("@/views/CommonConfig/application/applicationDetails/applicationDetails.vue"),
        name: "applicationDetails",
        hidden:true,
        meta: {
          title: "应用配置详情",
          roles: 'quote_admin',
          noCache: true,
        }
      }
    ]},
    {
      path: "/physical",
      component: Layout,
      redirect: "/physical/express",
      name: "physical",
      alwaysShow: true,
      meta: {
        title: "物流管理",
        icon: "wuliu",
        roles: 'logistic'
      },children : [{
        path: "/physical/express",
        component: () => import("@/views/physical/express/express"),
        name: "express",
        meta: {
          title: "渠道配置",
          roles:'logistic_comp',
          noCache: true,
        }
      },
      {
        path: "/physical/logistics",
        component: () => import("@/views/physical/logistics/logistics"),
        name: "logistics",
        meta: {
          title: "物流订单",
          roles:'logistic_order',
          noCache: true,
        }
      }
    ]},
    {
      path: "/note",
      component: Layout,
      redirect: "/note/Institution",
      name: "note",
      alwaysShow: true,
      meta: {
        title: "短信管理",
        icon: "message",
        roles: 'sms_menu'
      },children : [{
        path: "/note/signature",
        component: () => import("@/views/note/signature/signature"),
        name: "signature",
        meta: {
          title: "短信签名配置",
          roles:'sms_sign',
          noCache: true,
        },
      },{
        path: "/note/noteTemplate",
        component: () => import("@/views/note/noteTemplate/noteTemplate"),
        name: "noteTemplate",
        meta: {
          title: "短信模板配置",
          roles: 'sms_tpl',
          noCache: true,
        },
      },{
          path: "/note/sendNote",
          component: () => import("@/views/note/sendNote/sendNote"),
          name: "sendNote",
          meta: {
            title: "发送短信",
            roles: 'sms_tel_record',
            noCache: true,
          }
      },
    ]},
    {
      path: "/message",
      component: Layout,
      redirect: "/message/message",
      name: "message",
      alwaysShow: true,
      meta: {
        title: "消息管理",
        icon: "dashboard",
        roles: 'message'
      },children : [{
        path: "/message/msgManage",
        component: () => import("@/views/message/msgManage/msgManage"),
        name: "msgManage",
        meta: {
          title: "消息管理",
          roles:'msg_origin',
          noCache: true,
        }
      },
    ]},
    nestedRouter,
    productAdminRouter,
    appraiserAdminRouter,
    shoppingCentreRouter,
    userCentreRouter,
    warehouseCenter,
    marketing,
    payCenter,
    activity,
  { path: '*', redirect: '/404', hidden: true }

]
